package org.sandbox2.domain.invoice;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import javax.validation.constraints.NotNull;
import java.util.Date;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.format.annotation.DateTimeFormat;
import org.sandbox2.domain.loan.Borrower;
import javax.persistence.ManyToOne;

@RooJavaBean
@RooToString
@RooEntity
public class Invoice {

    @NotNull
    private Integer amount;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "S-")
    private Date dueDate;
    
    @ManyToOne
    private Borrower borrower;

	public int getPaymentGracePeriod() {
		if (borrower.getInGoodStanding()) {
			return 60;
		}
		return 30;
	}
}
